package org.jeecg.modules.engineering.service.demo;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.engineering.service.BaseDataClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class DemoClientService implements InitializingBean {
    @Autowired
    BaseDataClient baseDataClientService;

    public void testSimple(){
        long t1 = System.currentTimeMillis();
        int arg1 = 250;
        int arg2 = 1000;
        String op = "add";
        Result<Integer> res =  baseDataClientService.simple(op, arg1, arg2, 100L);
        String str = "远程调用计算: " +  arg1 + op + arg2;
        if (res.isSuccess()) str += " 成功 值=" + res.getResult();
        else str += " 失败， 原因:" + res.getMessage();

        log.info( str + " time:" + (System.currentTimeMillis() - t1));
    }
    public void testHight(){
        long t1 = System.currentTimeMillis();
        BaseDataClient.MyDate d = new BaseDataClient.MyDate();
        d.setArg1("thisisarg1");
        d.setArg2("thisisarg2");
        d.getInnerObj().put("id", 1);
        d.getInnerObj().put("id2", 1);
        d.getInnerObj().put("text", "1");
        Result<Object> res =  baseDataClientService.hight(d);
        String str = "远程调用取值: "; // + JSON.toJSONString(res);
        if (res.isSuccess()) str += " 成功 值=" + res.getResult();
        else str += " 失败， 原因:" + res.getMessage();
        log.info( str+ " time:" + (System.currentTimeMillis() - t1));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
 //       for (int i = 0; i < 1000 ; i++) {
  //          testSimple();
  //          testHight();
  //          Thread.sleep(1000);
  //      }

    }
}
